function SDX_Cells(_RootObject, _Row)
{
 this.RootObject = _RootObject ;
 this.Row = _Row ;
 this.Cells = new Array() ;
 this.Cell = SDX_Cell;
 this.InsertCell = InsertCell;
 this.GetCell = GetCell;
 this.Initialize = Initialize ;
 function InsertCell(_Field, _Column)
 {
  var cellID = this.Cells.length ;
  this.Cells[cellID]=new this.Cell(cellID, this.RootObject, this.Row, this.Row.Data.Data[_Column.ID] , _Field, _Column) ;
 }
 function GetCell(_FieldKey)
 {
  for(var nX in this.Cells)
  {
   if(this.Cells[nX].Column.Key == _FieldKey)
   {
    return this.Cells[nX]
   }
  }
 }
 function SDX_Cell(_ID, _RootObject, _Row, _Value, _Field, _Column)
 {
  this.RootObject = _RootObject ;
  this.Row = _Row ;
  this.ID = _ID
  this.GetEvalObjectString = GetEvalObjectString ;
  this.HTMLID = this.RootObject.Name + "_SDX_Row_" + this.Row.ID + "_Cell_" + this.ID;
  this.Value = _Value;
  this.BackupValue = null ;
  this.Field = _Field; // Field.Type -->  <0> Custom - <1> Single Line Text - <2> Multi Line Text <3> RichText Edit - <4> Password - <5> Button - <6> Image Button <7> Checkbox - <8> Radio Button - <9> ComboBox - <10> SelectBox - <11> File Upload
  this.Column = _Column ;
  this.NormalMode = NormalMode ;
  this.EditMode = EditMode ;
  this.SelectMode = SelectMode ;
  this.CancelEdit = CancelEdit ;
  this.OnClick = OnClick ;
  this.Selected = false;
  this.Edited = false;
  this.SetValue = SetValue ;
  this.RePaint = RePaint;
  this.HTMLOutPut = HTMLOutPut;
  function GetEvalObjectString()
  {
    return this.Row.GetEvalObjectString() + ".GetRowView().Cells.Cells[" + this.ID + "]" ;
  }
  function RePaint()
  {
    document.getElementById(this.HTMLID).innerHTML = this.Field.GetDisplayHTML(this.RootObject.Datas.CurrentDatas[this.Row.Data.KeyID].Data[this.Column.ID]);
  }
  function OnClick()
  {
   var isSelected = false
   if(this.RootObject.Rows.SelectedCell != null)
   {
       if(this.RootObject.Rows.SelectedCell.ID == this.ID && this.RootObject.Rows.SelectedCell.Row.ID == this.Row.ID)
       {
          this.RootObject.Rows.SelectedCell.EditMode();
          isSelected = true;
       }
       else
       {
           this.RootObject.Rows.SelectedCell.NormalMode() ;
       }
   }

   if(this.RootObject.Rows.EditedCell != null)
   {
       if(this.RootObject.Rows.EditedCell.ID == this.ID && this.RootObject.Rows.EditedCell.Row.ID == this.Row.ID)
       {
           isSelected = true;
       }
       else
           this.RootObject.Rows.EditedCell.NormalMode() ;
   }
   if(isSelected == false)
       this.SelectMode() ;   

  }
  function CancelEdit()
  {
   this.SetValue(this.BackupValue)
  }
  function EditMode()
  {
   if(this.Column.ReadOnly == true)
    return ;
   if(this.Edited == false)
   {
    this.Row.ChangeSelectionStatus(3)

    this.RootObject.Styles.RemoveFonts(document.getElementById(this.HTMLID).style)
    document.getElementById(this.HTMLID).innerHTML = this.Field.GetEditHTML(this);
    this.Field.Onload(this);
    this.RootObject.Rows.EditedCell = this ;
    this.RootObject.Rows.SelectedCell = null ;
    this.Edited = true
    this.BackupValue = this.Value ;
   }
  }
  function NormalMode()
  {
   this.Edited = false ;
   this.Selected = false ;
   this.BackupValue = null ;
   if(document.getElementById(this.HTMLID))
   {
    this.Row.ChangeSelectionStatus(0)
    this.RootObject.Styles.RemoveFonts(document.getElementById(this.HTMLID).style)
    document.getElementById(this.HTMLID).innerHTML = this.Field.GetDisplayHTML(this.RootObject.Datas.CurrentDatas[this.Row.Data.KeyID].Data[this.Column.ID]);
   }
  }
  function SelectMode()
  {
   this.RootObject.Rows.ClearSelectedRows();
   this.Row.ChangeSelectionStatus(1)
   this.Selected = true ;
   this.BackupValue = null ;
   this.RootObject.Styles.SetFont(document.getElementById(this.HTMLID).style,this.RootObject.Styles.SelectedItemStyle)
   this.RootObject.Rows.SelectedCell = this ;
   this.RootObject.Rows.EditedCell = null ;
  }
  function SetValue(_Value)
  {
   if(this.Row.Data.Data[this.Column.ID] != _Value)
   {
    this.RootObject.Datas.CurrentDatas[this.Row.Data.KeyID].Data[this.Column.ID] = _Value ;
    var modifiedData = this.RootObject.Datas.InsertModifiedData(this.Row.Data.KeyID) ;
    modifiedData.Data[this.Column.ID] = _Value ;
    this.Row.Data.Data[this.Column.ID] = _Value ;
   }
  }
  function HTMLOutPut()
  {
   return this.Field.GetDisplayHTML(this.Value);
  }
 }
 function Initialize()
 {
  for(var nX in this.RootObject.Columns.Columns)
  {
   this.InsertCell(this.RootObject.Columns.Columns[nX].Field,this.RootObject.Columns.Columns[nX])
  }
 }
}